<template>
    <div style="padding: 15px">
        <el-form ref="form" size="small" inline>
            <el-form-item label="是否可用:" prop="companyName">
                    <el-select
                        class="items"
                        v-model="isEnable"
                        size="small"
                    >
                        <el-option label="全部" value=''></el-option>
                        <el-option label="是" :value="1"></el-option>
                        <el-option label="否" :value="0"></el-option>
                    </el-select>
            </el-form-item>
            <el-button type="primary" size="small" @click="search"
                >查询</el-button
            >
        </el-form>
        <el-table
                :header-cell-style="headerCellStyle"
                size="small"
                :data="tableData"
                border
                style="width: 100%"
            >
                <el-table-column
                    prop="appPackageID"
                    label="应用包序号"
                    min-width="90"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="packageName"
                    label="应用包名称"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                 <el-table-column
                    prop="introducePicUrl"
                    label="应用包介绍图片地址"
                    min-width="160"
                    show-overflow-tooltip
                >
                <template slot-scope="scope">
                    <el-image
                    style="width: 100px; height: 80px"
                    :src="scope.row.introducePicUrl">
                    </el-image>
                </template>
                
                </el-table-column>
                <el-table-column
                    prop="introduceText"
                    label="应用包简介文本"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
               
                <el-table-column
                    prop="md5"
                    label="md5"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="appPackageType"
                    label="应用包类型"
                    min-width="160"
                    show-overflow-tooltip
                >
                <template slot-scope="scope">
                    <span>{{ scope.row.appPackageTypeName }}</span>
                </template>
                </el-table-column>
                <el-table-column
                    prop="auther"
                    label="应用包作者"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="packageUrl"
                    label="应用包下载地址"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="packageVersionCode"
                    label="应用包版本号"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                 <el-table-column
                    prop="internalPackageVersionCode"
                    label="应用包内部版本号"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="isOnshelf"
                    label="是否上架"
                    min-width="160"
                    show-overflow-tooltip
                >
                 <template slot-scope="scope">
                        {{ scope.row.isOnShelf === 1 ? '是' : '否' }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="isEnable"
                    label="是否禁用"
                    min-width="160"
                    show-overflow-tooltip
                >
                 <template slot-scope="scope">
                        {{ scope.row.isEnable === 1 ? '是' : '否' }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="remarks"
                    label="备注"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="createTime"
                    label="创建时间"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="upgradeTime"
                    label="更新时间"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column fixed="right" label="操作" width="200px">
                    <template slot-scope="scope">
                        <el-button type="primary" size="small" @click="shelves(scope.row)"
                        ><span v-if="scope.row.isEnable == 0">启用</span><span v-else>禁用</span>
                         </el-button>
                    </template>                    
                </el-table-column>
            </el-table>
        <div style="width: 100%; padding: 15px" class="right">
            <el-pagination
                background
                :current-page.sync="currentPage"
                @current-change="handleCurrentChange"
                :page-size="pageSize"
                layout="prev, pager, next, total"
                :total="totalNum"
            ></el-pagination>
        </div>
    </div>
</template>

<script>
export default {
    props: {
        value: Boolean,
        currRow: Object
    },
    data () {
        return {
            row: {},
            currentPage: 1,
            pageSize: 10,
            totalNum: 0,
            isShowUp: false,
            loading: false,
            tableData: [],
            showValue: false,
            terminalTypeList: [],
            packageFileTypeList: [],
            isEnable: ''
        }
    },
    watch: {
    },
    created () {
        this.getList()
    },
    methods: {
        showUp (row) {
            this.row = row
            this.isShowUp = true
        },
        search () {
            this.currentPage = 1
            this.getList()
        },
        handleCurrentChange (page) {
            // 换页
            this.currentPage = page
            this.getList()
        },
        shelves (row) {
            this.$confirm('确定执行此操作吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$http.post(this.$store.state.IP + '/appStore/packageIsEnableSwitch', {
                    appPackageID: row.appPackageID,
                    companyCode: this.currRow.companyCode,
                    isEnable: row.isEnable === 1 ? 0 : 1
                },
                    {
                        'emulateJSON': false
                    }
                ).then(response => {
                    console.log('-------------------------------------------')
                    response = response.body
                    console.log(response)
                    if (response.ret === '0') {
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        })
                        this.getList()
                    }
                }, response => {
                })
            }).catch(() => {
            })
        },
        // 获取列表
        async getList () {
            this.loading = true
            const res = await this.$http.post(this.$store.state.IP + '/appStore/appPackagePageForCompany', {
                companyCode: this.currRow.companyCode,
                page: this.currentPage - 1,
                size: 10,
                isEnable: this.isEnable
            })
            let response = res.data
            if (response.ret === '0') {
                this.loading = false
                this.tableData = response.res.list
                this.totalNum = response.res.total
            } else {
                this.loading = false
            }
        },
        // 清空数据
        clearData () {
            this.$refs['form'].resetFields()
            this.currentPage = 1
            this.showValue = false
            this.tableData = []
        }
    }
}
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped>
.item
    width: 110px

.right
    text-align: right
</style>